package com.chujian.framework.starter.log.service.impl;

import com.chujian.framework.starter.log.model.AuditLog;
import com.chujian.framework.starter.log.service.ILogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;

/**
 * 打印日志
 *
 * @author chujian
 * @since 2021-12-12
 */
@Slf4j
@Service
@ConditionalOnProperty(name = "chujian.log.audit.logType", havingValue = "logger", matchIfMissing = true)
public class DbLogService implements ILogService {

    private static final String MSG_PATTERN = "{} app:{} class:{} method:{} userId:{} userName:{} acId:{} log:{}";

    @Override
    public void saveAuditLog(AuditLog log) {
        DbLogService.log.debug(
                MSG_PATTERN
                , log.getTimestamp().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))
                , log.getApplicationName()
                , log.getClassName()
                , log.getMethodName()
                , log.getUserId()
                , log.getUserName()
                , log.getAcId()
                , log.getLog());
    }
}
